package cars;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.model.SelectItem;

@ManagedBean
@SessionScoped
public class CarsBean {
	private HashMap<Integer, CarObject> myCars = new HashMap<Integer, CarObject>();
	private List<SelectItem> carItems = new LinkedList<SelectItem>();
	private CarObject selectedCar;
	
	public CarsBean() {
		CarObject car_1 = new CarObject(1,"Ferrari");
		CarObject car_2 = new CarObject(2,"Logan");
		CarObject car_3 = new CarObject(3,"Fiat");
		CarObject car_4 = new CarObject(4,"Kia");
		CarObject car_5 = new CarObject(5,"Skoda");
		carItems.add(new SelectItem(car_1, car_1.getCarName()));
		myCars.put(car_1.getCarNumber(), car_1);
		carItems.add(new SelectItem(car_2, car_2.getCarName()));
		myCars.put(car_2.getCarNumber(), car_2);
		carItems.add(new SelectItem(car_3, car_3.getCarName()));
		myCars.put(car_3.getCarNumber(), car_3);
		carItems.add(new SelectItem(car_4, car_4.getCarName()));
		myCars.put(car_4.getCarNumber(), car_4);
		carItems.add(new SelectItem(car_5, car_5.getCarName()));
		myCars.put(car_5.getCarNumber(), car_5);
	}
	
	public CarObject getCar(Integer number) {
		return (CarObject) myCars.get(number);
	}
	
	public List<SelectItem> getCarItems() {
		return carItems;
	}
	
	public void setCarItems(List<SelectItem> carItems) {
		this.carItems = carItems;
	}
	
	public CarObject getSelectedCar() {
		return this.selectedCar;
	}
	
	public void setSelectedCar(CarObject selectedCar) {
		this.selectedCar = selectedCar;
	}
}
